#include<bits/stdc++.h>
using namespace std;
long long n,kyjs;
long long s[1010],c[1010];
string xh,ip;
struct aal
{
	string se;
	long long bh;
}kyj[1010];
int shu(int x)
{
	int k=0;
	for(int i=x;;i++)
	{
		if(ip[i]<'0'||ip[i]>'9')
		{
			break;
		}
		if(ip[i]>='0'||ip[i]<='9')
		{
			k=k*10+int(ip[i])-48;
		}
	}
	return k;
}
bool pd()
{
	long long l=ip.size(),js=0,js2=0,lj=0;
	bool b=true;
	for(int j=0;j<l;j++)
	{
		if(!js&&ip[j]=='0'&&(ip[j+1]>='0'||ip[j+1]<='9'))
		{
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		if((ip[j]<'0'||ip[j]>'9')&&ip[j]!='.'&&ip[j]!=':')
		{
			cout<<ip[j]<<" "<<j<<" ";
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		if(lj<3&&(ip[j]<'0'||ip[j]>'9')&&ip[j]==':')
		{
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		if(lj<3&&(ip[j]<'0'||ip[j]>'9')&&ip[j]!='.')
		{
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		if(lj==3&&(ip[j]<'0'||ip[j]>'9')&&ip[j]!=':')
		{
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		if(ip[j]=='.') lj++;
		if(ip[j]==':') js2=1;
		if(!js&&(ip[j+1]>='0'||ip[j+1]<='9')&&shu(j)>255&&js2==0)
		{
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		if(!js&&(ip[j+1]>='0'||ip[j+1]<='9')&&shu(j)>65535&&js2==1)
		{
			cout<<"ERR"<<endl;
			b=false;
			break;
		}
		js=1;
		if(ip[j]=='.'||ip[j]==':') js=0;
	}
	return b;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>xh>>ip;
		if(xh=="Server")
		{
			if(pd())
			{
				bool b1=true;
				for(int j=1;j<=kyjs;j++)
				{
					if(kyj[j].se==ip)
					{
						b1=false;
					}
				}
				if(b1)
				{
					kyj[++kyjs].se=ip;
					kyj[kyjs].bh=i;
					cout<<"OK"<<endl;
				}
				else
				{
					cout<<"FAIL"<<endl;
				}
			}
		}
		if(xh=="Client")
		{
			if(pd())
			{
				bool b1=true;
				for(int j=1;j<=kyjs;j++)
				{
					if(kyj[j].se==ip)
					{
						b1=false;
						cout<<kyj[j].bh<<endl;
						break;
					}
				}
				if(b1)
				{
					cout<<"FAIL"<<endl;
				}
			}
		}
	}
	return 0;
}
